package com.finalab.website.service.impl;


import com.finalab.website.dao.ProjectPOMapper;
import com.finalab.website.dao.po.ProjectPO;
import com.finalab.website.model.Project;
import com.finalab.website.service.ProjectService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProjectServiceImpl implements ProjectService {

    @Autowired
    ProjectPOMapper projectMapper;

    @Override
    public Project selectById(int id) {
        Project project = new Project();
        ProjectPO projectPO = projectMapper.selectByPrimaryKey(id);
        if(projectPO == null){
            return null;
        }
        BeanUtils.copyProperties(projectPO, project);
        return project;
    }

    @Override
    public List<ProjectPO> selectAll() {
//        PageHelper.startPage(offset, num);
        return projectMapper.selectAll();
    }

    @Override
    public void  insert(Project project){
        ProjectPO projectPO = new ProjectPO();
        BeanUtils.copyProperties(project, projectPO);
        projectMapper.insertSelective(projectPO);
    }

    @Override
    public void delete(int id){
        projectMapper.deleteByPrimaryKey(id);
    }


    @Override
    public void update(Project project){
        ProjectPO projectPO = new ProjectPO();
        BeanUtils.copyProperties(project, projectPO);
        projectMapper.updateByPrimaryKeySelective(projectPO);
    }
}
